import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-25
 * Time: 8:38
 */
//日常练习代码（草稿+熟悉各种轮子）
public class Test {

    public static int[] intersection(int[] nums1, int[] nums2) {
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int length1 = nums1.length, length2 = nums2.length;
        int[] intersection = new int[length1 + length2];
        int index = 0, index1 = 0, index2 = 0;
        while (index1 < length1 && index2 < length2) {
            int num1 = nums1[index1], num2 = nums2[index2];
            if (num1 == num2) {
                // 保证加入元素的唯一性
                if (index == 0 || num1 != intersection[index - 1]) {
                    intersection[index++] = num1;
                }
                index1++;
                index2++;
            } else if (num1 < num2) {
                index1++;
            } else {
                index2++;
            }
        }
        return Arrays.copyOfRange(intersection, 0, index);
    }

    public static void main(String[] args) {
        int[] nums1 = {1,2,3,4,5};
        int[] nums2 = {2,3};
        System.out.println(Arrays.toString(intersection(nums1, nums2)));
    }
    public static void main10(String[] args) {
        int a = 10;
        int[] arr = new int[a];
        arr[0] = 1;
        arr[1] = 2;
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(Arrays.copyOfRange(arr, 0, 2)));
    }
    public static int mySqrt(int x) {
        if(x < 1) return x;
        int count = 0;
        while(x/4 > 0){
            count++;
            x /= 4;
        }
        return count*2;
    }
    public static void main9(String[] args) {
        System.out.println(mySqrt(144));
//        int num = 8;
//        System.out.println((int)Math.pow(num,0.5));
    }

    public static void main8(String[] args) {
        String str1 = "ababcabesda";
        //截取
        String ret1 = str1.substring(1);
        String ret2 = str1.substring(1,5);//[1,5)左闭右开
        System.out.println(ret1);
        System.out.println(ret2);
    }
    public static void main7(String[] args) {
        String str1 = "ababcabesda";
        String ret1 = str1.replace('a','l');
        String ret2 = str1.replaceAll("ab","ly");
        //发生了向上转型
        String ret3 = str1.replace("ab","qw");
        System.out.println(ret1);
        System.out.println(ret2);
        System.out.println(ret3);
    }
    public static boolean func(String str){
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) > '9' || str.charAt(i) < '0'){
                return false;
            }
        }
        return true;
    }
    public static void main6(String[] args) {
        String str = "01asd4212";
        System.out.println(func(str));
    }
    public static void main5(String[] args) {
        String str1 = "HELLO";
        char[] ch = str1.toCharArray();
        System.out.println(Arrays.toString(ch));
    }
    public static void main4(String[] args) {
        String str1 = "HELLO";
        str1 = 'h' + str1.substring(1);
        System.out.println(str1);
    }
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        scanner.nextLine();
        String a = scanner.nextLine();
        String str1 = "hello";
        String str2 = "hel" + "lo";
        System.out.println(str1 == str2);
        String str3 = new String("hel") + "lo";
        System.out.println(str1 == str3);
    }
    public static void main1(String[] args) {
        String str1 = "hello";
        String str2 = "hello";
        String str3 = new String("hello");
        System.out.println(str1 == str3);
        System.out.println(str1 == str2);
    }
}
